package com.tianlang.domain.pojo;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * @author mcp
 *
 */
@Entity
@Table(name = "authority")
@GenericGenerator(name = "uuid", strategy = "uuid")
public class Authority {

	@Id
	@GeneratedValue(generator = "uuid")
	private String id;
	@Column
	private String name;
	/**
	 * @ManyToMany 指定多对多关系
	 * @Cascade 设置级联关系
	 * @JoinTable 指定第三张表
	 * joinColumns 本表与中间表的外键对应
	 */
	@ManyToMany
	@Cascade(value = { CascadeType.SAVE_UPDATE })
	@JoinTable(name = "role_authority", joinColumns = { @JoinColumn(name = "authorityId") }, inverseJoinColumns = {
			@JoinColumn(name = "roleId") })
	private List<Role> roles;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

}
